package cyx.example.ddd.domain.order.event;

import cyx.example.ddd.domain.order.model.aggregate.Order;
import cyx.example.ddd.domain.order.model.valueobject.Money;
import cyx.example.ddd.domain.shared.DomainEvent;
import lombok.Getter;

/**
 * 订单创建事件
 * 
 * 注意：这是一个示例实现，在实际企业项目中，可能需要考虑：
 * 1. 事件数据的最小化（只包含必要信息）
 * 2. 敏感信息的脱敏处理
 * 3. 事件数据的验证
 * 4. 事件版本升级策略
 */
@Getter
public class OrderCreatedEvent implements DomainEvent {
    
    private final String orderId;
    private final String userId;
    private final Money totalAmount;
    private final String currency;
    private final int itemCount;
    
    public OrderCreatedEvent(Order order) {
        this.orderId = order.getId();
        this.userId = order.getUserId();
        this.totalAmount = order.getTotalAmount();
        this.currency = order.getCurrency().getCurrencyCode();
        this.itemCount = order.getOrderItems().size();
    }
    
    @Override
    public String toString() {
        return String.format("OrderCreatedEvent{orderId='%s', userId='%s', totalAmount=%s, itemCount=%d}", 
                orderId, userId, totalAmount, itemCount);
    }
} 